package com.hctg.forced2sleep.utils;

import android.util.Base64;

import java.util.Arrays;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/**
 * description: 描述
 * company    :
 *
 * @author : ldf
 * date       : 2024/6/10 on 19
 * @version 1.0
 */
public class EncryptUtils {

    public static String des(String str) throws Exception {
        return des(str, "4jso$dkm#kkd*lsdk@");
    }

    public static String des(String str, String desKey) throws Exception {
        SecretKeySpec secretKeySpec = new SecretKeySpec(Arrays.copyOf(desKey.getBytes("UTF-8"), 24), "DESede");
        IvParameterSpec ivParameterSpec = new IvParameterSpec("01234567".getBytes());
        Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
        cipher.init(2, secretKeySpec, ivParameterSpec);
        return new String(cipher.doFinal(Base64.decode(str, 0)));
    }

    public static String des2(String str) throws Exception {
        SecretKeySpec secretKeySpec = new SecretKeySpec(Arrays.copyOf("4jso$dkm#kkd*lsdk@".getBytes("UTF-8"), 24), "DESede");
        IvParameterSpec ivParameterSpec = new IvParameterSpec("01234567".getBytes());
        Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
        cipher.init(1, secretKeySpec, ivParameterSpec);
        return Base64.encodeToString(cipher.doFinal(str.getBytes("UTF-8")), 0);
    }

}
